/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.RRHH;

import Controlador.Bean.Almacen.Almacen;
import Controlador.Bean.RRHH.*;
import Controlador.Bean.Seguridad.Perfil;
import gui.Almacen.DetalleGestionAlmacen;
import gui.Compras.OCSeleccionarProveedor;
import gui.General.Main;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import lib.Validaciones;

/**
 *
 * @author David
 */
public class MantenimientoEficiencias extends javax.swing.JInternalFrame {

      public class MyActionListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent evt) {
            JComboBox cb = (JComboBox) evt.getSource();
            Object selected = cb.getSelectedItem();

              if (selected.toString().equals("SELECCIONAR")){
                  txtIdEmpleado.setText("");
              }
              
              else{
              txtIdEmpleado.setText(selected.toString().substring(0,9));
              
              }
            
            
        }
    }


    
    
    
    
    
    /**
     * Creates new form detalleEmpleado
     */
    
    private TableModel tb;
    int clic=0;
    String selectedId;
    String tipo;
   
    
    
    public MantenimientoEficiencias() {
        initComponents();
        initComp();
      //  initTpMantenimientoEficiancias();
        
    }
    
        private void initTpMantenimientoEficiancias(){
        List<String> fases = new ArrayList<String>();
        fases.add("HORNEADO");
        fases.add("RELLENADO");
        fases.add("DECORADO");
        fases.add("EMPAQUETADO");
           
              
//            for(int i=0; i<fases.size(); i++){
//                     
//            jTabbedPane1.add(fases.get(i), new DetalleMantEfi(fases.get(i)));
//            jTabbedPane1.setMnemonicAt(i, KeyEvent.VK_1+i);
//        }
            

            
    }
    
    
     private void initComp(){
    
        tb = new TableModel();
        
          tblEmpleados.setModel(tb);
          tblEmpleados.setRowSelectionAllowed(true);
        
        cmbTurnos.removeAllItems();
        cmbTurnos.addItem("SELECCIONAR");
        cmbTurnos.addItem("MAÑANA");
        cmbTurnos.addItem("NOCHE");
        
//        cmbTipoMaquinas.removeAllItems();
//        cmbTipoMaquinas.addItem("SELECCIONAR");
//        cmbTipoMaquinas.addItem("HORNEADO");
//        cmbTipoMaquinas.addItem("DECORADO");
//        cmbTipoMaquinas.addItem("RELLENADO");
//        cmbTipoMaquinas.addItem("EMPAQUETADO");
        fecha.setDate(new Date());
        
        txtIdEmpleado.setEditable(false);
         
      //  cmbEmpleados.removeAllItems();
        // List<Personal> empleados = new ArrayList<>();
         //empleados = Controlador.Service.RRHH.GestionRRHH.obtenerObreros();
        //cmbEmpleados.addItem("SELECCIONAR");
        
//         for(int i=0; i<empleados.size(); i++){
//             cmbEmpleados.addItem(empleados.get(i).getIdEmpleado().concat("-").concat(empleados.get(i).getNombre()));
//         }
       
         //txtIdEmpleado.setText(cmbEmpleados.getSelectedItem().toString());
         //  MyActionListener actionListener = new MyActionListener();
        //cmbEmpleados.addActionListener(actionListener);
     
     }
    

   class TableModel extends AbstractTableModel{
        
        //Two arrays used for the table data
        String[] columnNames = {"ID","Turno", "TipoMaquina","Fecha", "Prod","Merma", "EsProm"};
               
        public List<DesempenoHistorico> data2 = Controlador.Service.RRHH.GestionRRHH.obtenerDesempenosHistorico();
                       
        
        //DesempeñoHistorico dh = new DesempenoHistorico("EMP000001","HORNEADO","MAÑANA",fecha,100.0,25.0,"1");
        
        public void actualizarTabla(){
           data2 = Controlador.Service.RRHH.GestionRRHH.obtenerDesempenosHistorico();
            
            fireTableDataChanged();
        }
        
            
        @Override
        public int getRowCount()
        {
           
            return data2.size();
        }
        
        
        
        @Override
        public int getColumnCount()            
        {
            return columnNames.length;
        }
         //
        
        @Override
        public Object getValueAt(int row, int column)
        {   
            switch(column){
                case 0: return data2.get(row).getIdEmpleadoOp();
                case 1: return data2.get(row).getTurno(); 
                case 2: return data2.get(row).getTipoMaquina();
                case 3: return data2.get(row).getFecha();
                case 4: return data2.get(row).getProduccion();
                case 5: return data2.get(row).getMerma();
                default: return data2.get(row).getEsPRom();
                 
            }
        }
        
        //Used by the JTable object to set the column names
        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
        
        //Used by the JTable object to render different
        //functionality based on the data type
        @Override
        public Class getColumnClass(int c) {
            
           return getValueAt(0, c).getClass();
           
        }
        
        @Override
        public boolean isCellEditable(int row, int column)
        {
	        return false;
        }
        
     }
    
    
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cmbTurnos = new javax.swing.JComboBox();
        fecha = new org.jdesktop.swingx.JXDatePicker();
        jLabel7 = new javax.swing.JLabel();
        txtIdEmpleado = new javax.swing.JTextField();
        btnEmpleados = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        txtPHorneado = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtMHorneado = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        txtPRellenado = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtMRellenado = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        txtPDecorado = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        txtMDecorado = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        txtPEmpaquetado = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        txtMEmpaquetado = new javax.swing.JTextField();
        btnCargar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        btnProm = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblEmpleados = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();

        setClosable(true);
        setTitle("Eficiencias de trabajadores");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos de busqueda"));

        jLabel1.setText("Codigo:");

        jLabel4.setText("Turno:");

        cmbTurnos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel7.setText("Fecha:");

        txtIdEmpleado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdEmpleadoActionPerformed(evt);
            }
        });

        btnEmpleados.setText("Seleccionar Empleado");
        btnEmpleados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmpleadosActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Horneado"));

        jLabel8.setText("Prod:");

        jLabel9.setText("Merma");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtPHorneado, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                    .addComponent(txtMHorneado))
                .addGap(28, 28, 28))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtPHorneado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtMHorneado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Rellenado"));

        jLabel10.setText("Prod:");

        jLabel11.setText("Merma");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtPRellenado, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                    .addComponent(txtMRellenado))
                .addGap(22, 22, 22))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtPRellenado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtMRellenado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Decorado"));

        jLabel12.setText("Prod:");

        jLabel13.setText("Merma");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtPDecorado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMDecorado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12)
                    .addComponent(txtPDecorado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtMDecorado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Empaquetado"));

        jLabel14.setText("Prod:");

        jLabel15.setText("Merma");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtPEmpaquetado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMEmpaquetado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel14)
                    .addComponent(txtPEmpaquetado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtMEmpaquetado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnCargar.setText("Cargar");
        btnCargar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCargarActionPerformed(evt);
            }
        });

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnProm.setText("Promedio");
        btnProm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPromActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel1))
                .addGap(69, 69, 69)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtIdEmpleado)
                    .addComponent(cmbTurnos, 0, 119, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnEmpleados)
                .addGap(40, 40, 40)
                .addComponent(jLabel7)
                .addGap(27, 27, 27)
                .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(71, 71, 71))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnCargar)
                .addGap(28, 28, 28)
                .addComponent(btnLimpiar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnProm)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel1)
                    .addComponent(txtIdEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEmpleados))
                .addGap(29, 29, 29)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cmbTurnos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCargar)
                    .addComponent(btnLimpiar)
                    .addComponent(btnProm)))
        );

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        tblEmpleados.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        tblEmpleados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblEmpleados);

        jLabel5.setText("Eficiencias por trabajador");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel5)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(169, Short.MAX_VALUE))
        );

        jPanel2.getAccessibleContext().setAccessibleName("Datos de Empleado");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        // TODO add your handling code here:
        
        cmbTurnos.setSelectedItem("SELECCIONAR");
        fecha.setDate(new Date());
        txtIdEmpleado.setText("");
        txtPHorneado.setText("");
        txtMHorneado.setText("");

        txtPRellenado.setText("");
        txtMRellenado.setText("");

        txtPDecorado.setText("");
        txtMDecorado.setText("");

        txtPDecorado.setText("");
        txtMDecorado.setText("");
        
        
    }//GEN-LAST:event_btnLimpiarActionPerformed

    
    
    
     public boolean valido(){
        

        
        boolean b = false;
        
        String n1 = "";
        String n2="";
        String n3 = "";
        String n4="";
        String n5 = "";
        String n6="";
        String n7="";
        String n8="";
        String n9 = "";
        String n10 = "";
      
        boolean prodH = Validaciones.validarEntero(txtPHorneado.getText());
        boolean mermaH= Validaciones.validarEntero(txtMHorneado.getText());
        
        boolean prodR = Validaciones.validarEntero(txtPRellenado.getText());
        boolean mermaR= Validaciones.validarEntero(txtMRellenado.getText());
        
        boolean prodD = Validaciones.validarEntero(txtPDecorado.getText());
        boolean mermaD= Validaciones.validarEntero(txtMDecorado.getText());
        
        boolean prodE = Validaciones.validarEntero(txtPEmpaquetado.getText());
        boolean mermaE= Validaciones.validarEntero(txtMEmpaquetado.getText());
        
 
         if (!txtIdEmpleado.getText().isEmpty() && !txtPHorneado.getText().isEmpty()
                 && !txtMHorneado.getText().isEmpty() && !txtPRellenado.getText().isEmpty()
                 && !txtMRellenado.getText().isEmpty() && !txtPDecorado.getText().isEmpty()
                 && !txtMDecorado.getText().isEmpty() && !txtPEmpaquetado.getText().isEmpty()
                 && !txtMEmpaquetado.getText().isEmpty()
                 && (cmbTurnos.getSelectedIndex()!=0)) {

             b = true;
         }
         
         else{
         
             b = false;
             n9 ="Los campos no deben estar vacios";
     }
         
           if(!prodH && !txtPHorneado.getText().isEmpty()){
           b = false;
           n1 =  "Error en Produccion fase horneado";
             
         }
           
            if(!mermaH && !txtMHorneado.getText().isEmpty()){
           b = false;
           n2 =  "Error en Merma fase horneado";
             
         }
            
             if(!prodR && !txtPRellenado.getText().isEmpty()){
           b = false;
           n3 =  "Error en Produccion fase rellenado";
             
         }
             
              if(!mermaH && !txtMRellenado.getText().isEmpty()){
           b = false;
           n4 =  "Error en Merma fase rellenado";
             
         }
              
           if(!prodR && !txtPDecorado.getText().isEmpty()){
           b = false;
           n5 =  "Error en Produccion fase decorado";
             
         }
           
           if(!mermaH && !txtMDecorado.getText().isEmpty()){
           b = false;
           n6 =  "Error en Merma fase decorado";
             
         }
           
                 if(!prodE && !txtPEmpaquetado.getText().isEmpty()){
           b = false;
           n7 =  "Error en Produccion fase empaquetado";
             
         }
           
           if(!mermaE && !txtMEmpaquetado.getText().isEmpty()){
           b = false;
           n8 =  "Error en Merma fase empaquetado";
             
         }
            if(cmbTurnos.getSelectedIndex()<1){
            b = false;
            n9 = "Seleccionar Turno";
        }
             
           
            String rpta="";
         if (n10!="") rpta = rpta+ n10 + "\n";
         if (n1!="") rpta = rpta+ n1 + "\n";
         if (n2!="") rpta = rpta+ n2 + "\n";
         if (n3!="") rpta = rpta+ n3 + "\n";
         if (n4!="") rpta = rpta+ n4 + "\n";
         if (n5!="") rpta = rpta+ n5 + "\n";
         if (n6!="") rpta = rpta+ n6 + "\n";
         if (n7!="") rpta = rpta+ n7 + "\n";
         if (n8!="") rpta = rpta+ n8 + "\n";
         if (n9!="") rpta = rpta+ n9 + "\n";

                
         if (rpta!="")
         JOptionPane.showMessageDialog(null, "Errores: \n" + rpta );
         
        
          return b;
    }
    
    
    
    private void btnCargarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCargarActionPerformed

        //Personal np = new Personal(txtIdEmpleado.getText(), txtNombre.getText(), txtApellidoPaterno.getText(), txtApellidoMaterno.getText(), tipo, txtNumeroDocumento.getText(), fecha, cmbHorario.getSelectedItem().toString(), "ACTIVO", cmbTipoEmp.getSelectedItem().toString());
        Date fechaLeida = fecha.getDate();
        String tipomaquina= "";
        String turno= "";
     
  
        
         if (valido()){
             
                 if (cmbTurnos.getSelectedItem().toString().equals("MAÑANA")) {
            turno = "TUR000001";

        }
        
        else  if (cmbTurnos.getSelectedItem().toString().equals("NOCHE")) {
            turno = "TUR000002";

        }
        
        //txtIdEmpleado.setText(cmbEmpleados.getSelectedItem().toString());
        String id = txtIdEmpleado.getText();
                
        DesempenoHistorico dh1 = new DesempenoHistorico(id, "TMA000001", turno, fechaLeida, Double.parseDouble(txtPHorneado.getText()), Double.parseDouble(txtMHorneado.getText()),"1");
        DesempenoHistorico dh2 = new DesempenoHistorico(id, "TMA000002", turno, fechaLeida, Double.parseDouble(txtPRellenado.getText()), Double.parseDouble(txtMRellenado.getText()),"1");
        DesempenoHistorico dh3 = new DesempenoHistorico(id, "TMA000003", turno, fechaLeida, Double.parseDouble(txtPDecorado.getText()), Double.parseDouble(txtMDecorado.getText()),"1");
        DesempenoHistorico dh4 = new DesempenoHistorico(id, "TMA000004", turno, fechaLeida, Double.parseDouble(txtPEmpaquetado.getText()), Double.parseDouble(txtMEmpaquetado.getText()),"1");
            
        try {
                Controlador.Service.RRHH.GestionRRHH.agregarDesempeno(dh1);
            } catch (Exception ex) {
                Logger.getLogger(MantenimientoEficiencias.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Controlador.Service.RRHH.GestionRRHH.agregarDesempeno(dh2);
            } catch (Exception ex) {
                Logger.getLogger(MantenimientoEficiencias.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Controlador.Service.RRHH.GestionRRHH.agregarDesempeno(dh3);
            } catch (Exception ex) {
                Logger.getLogger(MantenimientoEficiencias.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Controlador.Service.RRHH.GestionRRHH.agregarDesempeno(dh4);
            } catch (Exception ex) {
                Logger.getLogger(MantenimientoEficiencias.class.getName()).log(Level.SEVERE, null, ex);
            }
        
        JOptionPane.showMessageDialog(this, "Se han agregado correctamente los datos", "Confirmación", JOptionPane.INFORMATION_MESSAGE);
           
        tb.actualizarTabla();
            txtIdEmpleado.setText("");
            txtPHorneado.setText("");
            txtMHorneado.setText("");
            
            txtPRellenado.setText("");
            txtMRellenado.setText("");
            
            txtPDecorado.setText("");
            txtMDecorado.setText("");
            
            txtPEmpaquetado.setText("");
            txtMEmpaquetado.setText("");
            
            fecha.setEditable(true);
            cmbTurnos.setEnabled(true);
            cmbTurnos.setSelectedIndex(0);
      //      cmbTipoMaquinas.setEnabled(true);
           
        }
        
        
        
    }//GEN-LAST:event_btnCargarActionPerformed
  private double hallarPromProd(List<DesempenoHistorico> data){
       
       double suma=0;
       int i; 
       for (i=0; i< data.size(); i++){     
           suma= suma + data.get(i).getProduccion();
       }
       if(data.size()>0){
            return (suma/i);
       }else{
           return (suma/1);
       }
   }
 
   
     private double hallarPromMerma(List<DesempenoHistorico> data){
       
       int j=1;
       double suma=0;
         
       for (int i=0; i< data.size(); i++){
           
           suma= suma + data.get(i).getMerma();
           j=i;
       }
       
       return (suma/(j+1));
   }
    
   
   
     
    
    
    private void btnPromActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPromActionPerformed

       String flag;
       String id;
       int numFilas=0;
       
       if (txtIdEmpleado.getText().isEmpty()){
           JOptionPane.showMessageDialog(this, "Error al hallar promedio", "Ingrese un ID", JOptionPane.OK_OPTION);
           
       }
       else{
                id=txtIdEmpleado.getText();
                numFilas = Controlador.Service.RRHH.GestionRRHH.contarFilasDesempeno(id);
                String numFilasS = Integer.toString(numFilas);
                int numTurnos=2;
                int numMaquinas =4;
                int numMeses = 6;
                ArrayList<String> tipoMaquinas = new ArrayList<String>();
                ArrayList<String> turnos = new ArrayList<String>();
             
                tipoMaquinas.add("TMA000001");
                tipoMaquinas.add("TMA000002");
                tipoMaquinas.add("TMA000003");
                tipoMaquinas.add("TMA000004");
                
                turnos.add("TUR000001");
                turnos.add("TUR000002");
                
           double promProduccion;
           double promMerma;
           
                    
           int m = 0;
           int t = 0;
           List<DesempenoHistorico> data = new ArrayList<>();
           while (m < tipoMaquinas.size()) {
               while (t < turnos.size()) {
                 data.addAll(Controlador.Service.RRHH.GestionRRHH.obtenerListaDesempeno(tipoMaquinas.get(m),turnos.get(t),id));
                 
                  //System.out.println(data.get(total).getProduccion());
                  promProduccion = hallarPromProd(data);
                  promMerma = hallarPromMerma(data);
                  Date date= new Date();
                  DesempenoHistorico dh = new DesempenoHistorico(id, tipoMaquinas.get(m), turnos.get(t), date, promProduccion,promMerma,"1");
                   try {
                       Controlador.Service.RRHH.GestionRRHH.agregarDesempeno(dh);
                   } catch (Exception ex) {
                       Logger.getLogger(MantenimientoEficiencias.class.getName()).log(Level.SEVERE, null, ex);
                   }
                  t++;
               }
               m++;
           }
                    
      tb.actualizarTabla();
       
       } 
        
         
    }//GEN-LAST:event_btnPromActionPerformed

    private void txtIdEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdEmpleadoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdEmpleadoActionPerformed

    private void btnEmpleadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmpleadosActionPerformed
        // TODO add your handling code here:
        
       SeleccionarEmpleado se=new SeleccionarEmpleado();
        Main.getDesktop().add(se);
        se.setVisible(true);

    }//GEN-LAST:event_btnEmpleadosActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCargar;
    private javax.swing.JButton btnEmpleados;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnProm;
    private javax.swing.JComboBox cmbTurnos;
    private org.jdesktop.swingx.JXDatePicker fecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblEmpleados;
    public static javax.swing.JTextField txtIdEmpleado;
    private javax.swing.JTextField txtMDecorado;
    private javax.swing.JTextField txtMEmpaquetado;
    private javax.swing.JTextField txtMHorneado;
    private javax.swing.JTextField txtMRellenado;
    private javax.swing.JTextField txtPDecorado;
    private javax.swing.JTextField txtPEmpaquetado;
    private javax.swing.JTextField txtPHorneado;
    private javax.swing.JTextField txtPRellenado;
    // End of variables declaration//GEN-END:variables
}
